home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / pascal / tvtool2.zip / SCROLL.PAS < prev    next >
Pascal/Delphi Source File  |  1993-07-20  |  10KB  |  403 lines

  1. {*
  2. *   TV Tool Box Version 2.0
  3. *   Copyright 1992,93 by Richard W. Hansen, All Rights Reserved.
  4. *
  5. *
  6. *   Demo.pas
  7. *   A demo of TV TOOL BOX for Turbo Pascal 7.0.
  8. *
  9. *}
  10.  
  11. PROGRAM TV_SCROLL_TEST;
  12. {$X+}
  13.  
  14. USES
  15.   TvConst, TvScroll,
  16.   Objects, Drivers, Views, Menus, Dialogs, App;
  17.  
  18.  
  19. CONST
  20.   cmTestW  = 100;
  21.   cmTestD  = 101;
  22.  
  23.             {         1         2         3         4         5         6         7         8         9         0}
  24.             {1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890}
  25.   Line1   = '┌─ These are Draggable and Resizable, press Tab to try some input lines.───┬────┬────┬────┬────┬────┐';
  26.   Line2   = '│    │    │    │    │    │    │    │    │    │    │    │    │    │    │    │    │    │    │    │    │';
  27.   Line3   = '├────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┼────┤';
  28.  
  29.  
  30. TYPE
  31.   TMyApp = object(TApplication)
  32.     Constructor Init;
  33.     Procedure   HandleEvent(var Event: TEvent);           virtual;
  34.     Procedure   InitMenuBar;                              virtual;
  35.     Procedure   InitStatusLine;                           virtual;
  36.     Procedure   TestWindow;
  37.     Procedure   TestDialog;
  38.   end;
  39.  
  40.   PMyView1 = ^TMyView1;
  41.   TMyView1 = Object(TView)
  42.     Procedure   Draw;                                     Virtual;
  43.   end;
  44.  
  45.   PMyView2 = ^TMyView2;
  46.   TMyView2 = Object(TView)
  47.     Procedure   Draw;                                     Virtual;
  48.   end;
  49.  
  50.   PMyView3 = ^TMyView3;
  51.   TMyView3 = Object(TbxScrollView)
  52.     Procedure   Draw;                                     Virtual;
  53.     Procedure   SizeLimits(var Min, Max : TPoint);        Virtual;
  54.   end;
  55.  
  56.   PMyWindow = ^TMyWindow;
  57.   TMyWindow = Object(TbxScrollWindow)
  58.     Function    InitBackground: PView;                    Virtual;
  59.   end;
  60.  
  61.  
  62. { TMyView3 }
  63. { Scrolling, selectable views }
  64. Procedure TMyView3.Draw;
  65.  
  66.   var
  67.     B : TDrawBuffer;
  68.     C : Word;
  69.  
  70.   begin
  71.     { set colors for the various modes. }
  72.     if (State AND sfDragging <> 0) and (State AND sfSelected <> 0) then
  73.       C := 3
  74.     else if (State AND sfFocused <> 0) then
  75.       C := 2
  76.     else
  77.       C := 1;
  78.  
  79.     MoveChar(B, 'X', GetColor(C), Size.X);
  80.     WriteLine(0, 0, Size.X, Size.Y, B);
  81.   end;
  82.  
  83. Procedure TMyView3.SizeLimits(var Min, Max : TPoint);
  84.   begin
  85.     { only grow in X dimension }
  86.     Min.X := 1;
  87.     Min.Y := 1;
  88.     Max.X := Owner^.Size.X;
  89.     Max.Y := 1;
  90.   end;
  91.  
  92.  
  93. { TMyView2 }
  94. { Scrolling background }
  95. Procedure TMyView2.Draw;
  96.  
  97.   var
  98.     C : Word;
  99.     Y : Word;
  100.     X : Word;
  101.     I : Integer;
  102.     T : String[5];
  103.     S : String;
  104.  
  105.   begin
  106.     if State and sfFocused <> 0 then
  107.       C := $0002
  108.     else
  109.       C := $0001;
  110.  
  111.     { Display the currently visible portion of the background }
  112.     Y := PbxScrollGroup(Owner)^.VScrollBar^.Value;
  113.     X := PbxScrollGroup(Owner)^.HScrollBar^.Value + 1;
  114.  
  115.     for I := 0 to Size.Y - 1 do
  116.     begin
  117.       if (Y = 0) then
  118.         S := Copy(Line1, X, Size.X)
  119.       else if (Y MOD 3 = 0) then
  120.         S := Copy(Line3, X, Size.X)
  121.       else
  122.         S := Copy(Line2, X, Size.X);
  123.  
  124.       Inc(Y);
  125.       Str(Y:3, T);
  126.       S[Length(S) - 1] := T[3];
  127.       S[Length(S) - 2] := T[2];
  128.       S[Length(S) - 3] := T[1];
  129.  
  130.       WriteStr(0, I, S, C);
  131.     end;
  132.   end;
  133.  
  134.  
  135. { TMyView1 }
  136. { Scrolling non-selectable views }
  137. Procedure TMyView1.Draw;
  138.  
  139.   var
  140.     B : TDrawBuffer;
  141.     C : Word;
  142.  
  143.   begin
  144.     if State and sfFocused <> 0 then
  145.     begin
  146.       C := $0002;
  147.     end
  148.     else
  149.     begin
  150.       C := $0001;
  151.     end;
  152.  
  153.     MoveChar(B, '*', GetColor(C), Size.X);
  154.     WriteLine(0, 0, Size.X, Size.Y, B);
  155.   end;
  156.  
  157.  
  158. Function TMyWindow.InitBackground: PView;
  159.  
  160.   var
  161.     R : TRect;
  162.     P : PView;
  163.  
  164.   begin
  165.     Interior^.GetExtent(R);
  166.     P := New(PMyView2, Init(R));
  167.     P^.SetState(sfDisabled, True);
  168.     P^.Options  := P^.Options AND not ofSelectable;
  169.     P^.GrowMode := P^.GrowMode OR gfGrowHiX OR gfGrowHiY;
  170.     InitBackground := P;
  171.   end;
  172.  
  173.  
  174. { TMyApp }
  175.  
  176. Procedure TMyApp.HandleEvent(var Event: TEvent);
  177.   begin
  178.     TApplication.HandleEvent(Event);
  179.  
  180.     if Event.What = evCommand then
  181.     begin
  182.       case Event.Command of
  183.         {cmTestW : TestWindow;}
  184.         cmTestD : TestDialog;
  185.         cmTestW : TestWindow;
  186.       else
  187.         Exit;
  188.       end;
  189.  
  190.       ClearEvent(Event);
  191.     end;
  192.   end;
  193.  
  194. Procedure TMyApp.InitMenuBar;
  195.  
  196.   var
  197.     R: TRect;
  198.  
  199.   begin
  200.     GetExtent(R);
  201.     R.B.Y := R.A.Y + 1;
  202.     MenuBar := New(PMenuBar, Init(R, NewMenu(
  203.       NewSubMenu('~T~est', hcNoContext, NewMenu(
  204.         NewItem('Test ~W~indow', 'F4', kbF4, cmTestW, hcNoContext,
  205.         NewItem('Test ~D~ialog', 'F5', kbF4, cmTestD, hcNoContext,
  206.         NewLine(
  207.         NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit, hcNoContext,
  208.         nil))))),
  209.       nil))
  210.     ));
  211.   end;
  212.  
  213. Procedure TMyApp.InitStatusLine;
  214.  
  215.   var
  216.     R: TRect;
  217.  
  218.   begin
  219.     GetExtent(R);
  220.     R.A.Y := R.B.Y - 1;
  221.     StatusLine := New(PStatusLine, Init(R,
  222.       NewStatusDef(0, $FFFF,
  223.         NewStatusKey('', kbF10, cmMenu,
  224.         NewStatusKey('~Alt-X~ Exit',      kbAltX, cmQuit,
  225.         NewStatusKey('~F2~ Resize Window',kbF2,   cmResize,
  226.         NewStatusKey('~F3~ Resize Field', kbF3,   cmDragView,
  227.         NewStatusKey('~F4~ New Window',   kbF4,   cmTestW,
  228.         NewStatusKey('~F5~ New Dialog',   kbF5,   cmTestD,
  229.         NewStatusKey('~F6~ Next Window',  kbF6,   cmNext,
  230.         nil))))))),
  231.       nil)
  232.     ));
  233.   end;
  234.  
  235. Procedure TMyApp.TestDialog;
  236.  
  237.   var
  238.     Dlg : PbxScrollDialog;
  239.     R   : TRect;
  240.     P   : PView;
  241.     i   : Integer;
  242.  
  243.   begin
  244.     R.Assign(0,0,44,19);
  245.     New(Dlg, Init(R, 'Test Dialog', ofVScrollBar or ofHScrollBar));
  246.  
  247.     with Dlg^ do
  248.     begin
  249.       Options := Options OR ofCentered;
  250.       { Make sure to set the size limits so the scrolling can be controlled. }
  251.       SetLimit(60, 30);
  252.  
  253.       { add a label }
  254.       { any view can be inserted to scroll, just set the scroll flag }
  255.       R.Assign(10,0,30,1);
  256.       P := New(PStaticText, Init(R, 'Scrolling Data Entry'));
  257.       InsertToScroll(P);
  258.  
  259.       { add some input lines }
  260.       for i := 1 to 12 do
  261.       begin
  262.         R.Assign(5,i + 1, 20, i + 2);
  263.         P := New(PInputLine, Init(R, 12));
  264.         InsertToScroll(P);
  265.       end;
  266.  
  267.       { add check boxes }
  268.       R.Assign(23,2,34,6);
  269.       P := New(PCheckBoxes, Init(R,
  270.         NewSItem('~O~ne',
  271.         NewSItem('~T~wo',
  272.         NewSItem('Th~r~ee',
  273.         NewSItem('~F~our',Nil))))));
  274.       PCluster(P)^.Value := 0;
  275.       InsertToScroll(P);
  276.  
  277.       { add radio buttons }
  278.       R.Assign(23,8,34,12);
  279.       P := New(PRadioButtons, Init(R,
  280.         NewSItem('~O~ne',
  281.         NewSItem('~T~wo',
  282.         NewSItem('Th~r~ee',
  283.         NewSItem('~F~our',Nil))))));
  284.       PCluster(P)^.Value := 0;
  285.       InsertToScroll(P);
  286.  
  287.       { add some more input lines }
  288.       for i := 1 to 12 do
  289.       begin
  290.         R.Assign(38,i + 1, 53, i + 2);
  291.         P := New(PInputLine, Init(R, 12));
  292.         InsertToScroll(P);
  293.       end;
  294.  
  295.       { add more radio buttons }
  296.       R.Assign(23,13,34,17);
  297.       P := New(PRadioButtons, Init(R,
  298.         NewSItem('~O~ne',
  299.         NewSItem('~T~wo',
  300.         NewSItem('Th~r~ee',
  301.         NewSItem('~F~our',Nil))))));
  302.       PCluster(P)^.Value := 0;
  303.       InsertToScroll(P);
  304.  
  305.       { Add some buttons, these can scroll too, as you see fit.
  306.         It kind of depends on how your dialog box is layed out.
  307.         But make sure to insert them into the scrolling group, not
  308.         directly into the dialog box. If buttons are inserted into
  309.         the dialog and not the scrolling group, the tab order gets
  310.         messed up.
  311.       }
  312.       R.Assign(6,20,14,22);
  313.       P := New(PButton, Init(R, 'O~K~', cmOK, bfDefault));
  314.       InsertToScroll(P);
  315.  
  316.       R.Assign(26,20,38,22);
  317.       P := New(PButton, Init(R, '~C~ancel', cmCancel, bfNormal));
  318.       InsertToScroll(P);
  319.  
  320.       Interior^.SelectNext(False);
  321.     end;
  322.  
  323.     Desktop^.ExecView(Dlg);
  324.     Dispose(Dlg, Done);
  325.   end;
  326.  
  327. Procedure TMyApp.TestWindow;
  328.  
  329.   var
  330.     Win : PMyWindow;
  331.     i   : Integer;
  332.     P   : PView;
  333.     R   : TRect;
  334.     S   : PScroller;
  335.  
  336.   begin
  337.     R.Assign(0, 0, 40, 15);
  338.     Win := New(PMyWindow, Init(R, 'Demo Window', wnNoNumber, ofVScrollBar or ofHScrollBar));
  339.     { Make sure to set the size limits so the scrolling can be controlled. }
  340.     Win^.SetLimit(100,30);
  341.     {Win^.AutoPosition(False);}
  342.  
  343.     { Add some views that scroll, and can be resized and dragged. }
  344.     for i := 1 to 7 do
  345.     begin
  346.       R.Assign(i,i, i + i * 2, i + 1);
  347.       P := New(PMyView3, Init(R));
  348.       Win^.InsertToScroll(P);
  349.     end;
  350.  
  351.     { Add some views that scroll, but cannot be resized or dragged.
  352.       You could also add views that do not scroll at all, just by
  353.       cleared the gfGrowXYRel bit in the GrowMode.
  354.     }
  355.     for i := 1 to 7 do
  356.     begin
  357.       R.Assign(1,i + 9, i * i + 1, i + 10);
  358.       P := New(PMyView1, Init(R));
  359.       Win^.InsertToScroll(P);
  360.     end;
  361.  
  362.     { add some scrolling input lines }
  363.     for i := 1 to 2 do
  364.     begin
  365.       R.Assign(1,i + 18, 9, i + 19);
  366.       P := New(PbxScrollInputLine, Init(R, 6));
  367.       Win^.InsertToScroll(P);
  368.     end;
  369.  
  370.     R.Assign(1,i + 20, 9, i + 21);
  371.     P := New(PbxScrollInputLine, Init(R, 15));
  372.     Win^.InsertToScroll(P);
  373.  
  374.     { Always insert the window after it is setup, (after first view
  375.       has been inserted) this will avoid some unsightly screen displays on
  376.       slower machines.
  377.     }
  378.     DeskTop^.Insert(Win);
  379.   end;
  380.  
  381. Constructor TMyApp.Init;
  382.  
  383.   var
  384.     E : TEvent;
  385.  
  386.   begin
  387.     TApplication.Init;
  388.     E.What := evCommand;
  389.     E.Command := cmTestD;
  390.     E.InfoPtr := nil;
  391.     PutEvent(E);
  392.   end;
  393.  
  394.  
  395. VAR
  396.   MyApp : TMyApp;
  397.  
  398. BEGIN
  399.   MyApp.Init;
  400.   MyApp.Run;
  401.   MyApp.Done;
  402. END.
  403.